﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter21
{
    using Chapter21.Models;
    using System.Windows;

    public class MainWindowViewModel
    {
        private List<Unit> unit;

        public MainWindowViewModel()
        {
            unit = new List<Unit>();
            unit.Add(new Unit { Num = 1, Title = "概述" });
            unit.Add(new Unit
            {
                Num = 2,
                Title = "Parallel 类",
                Sample = "ParallelSamples",
                ChildCatalogues = new List<Unit> 
                { 
                    new Unit { Num = 2.1, Title = "用 Parallel.For() 方法循环" }, 
                    new Unit { Num = 2.2, Title = "使用 Parallel.ForEach() 方法循环" },
                    new Unit { Num = 2.3, Title = "通过 Parallel.Invoke() 方法调用多个方法" } 
                }
            });
            unit.Add(new Unit
            {
                Num = 3,
                Title = "任务",
                Sample = "TaskSamples",
                ChildCatalogues = new List<Unit> 
                { 
                    new Unit { Num = 3.1, Title = "启动任务" }, 
                    new Unit { Num = 3.2, Title = "Futrue 任务的结果" },
                    new Unit { Num = 3.3, Title = "连续的任务" }, 
                    new Unit { Num = 3.4, Title = "任务的层次结构" } 
                }
            });
            unit.Add(new Unit
            {
                Num = 4,
                Title = "取消架构",
                Sample = "CancellationSamples",
                ChildCatalogues = new List<Unit> 
                { 
                    new Unit { Num = 4.1, Title = "Parallel.For() 方法的取消" }, 
                    new Unit { Num = 4.2, Title = "任务的取消" },
                }
            });
            unit.Add(new Unit { Num = 5, Title = "线程池", Sample = "ThreadPoolSamples" });
            unit.Add(new Unit
            {
                Num = 6,
                Title = "Thread 类",
                Sample = "ThreadSamples",
                ChildCatalogues = new List<Unit> 
                { 
                    new Unit { Num = 6.1, Title = "给线程传送数据" }, 
                    new Unit { Num = 6.2, Title = "后台线程" },
                    new Unit { Num = 6.3, Title = "线程的优先线" },
                    new Unit { Num = 6.4, Title = "控制线程" }
                }
            });
            unit.Add(new Unit
            {
                Num = 7,
                Title = "线程问题",
                Sample = "ThreadingIssues",
                ChildCatalogues = new List<Unit> 
                { 
                    new Unit { Num = 7.1, Title = "争用条件" }, 
                    new Unit { Num = 7.2, Title = "死锁" },
                    new Unit { Num = 7.3, Title = "线程的优先线" },
                    new Unit { Num = 7.4, Title = "控制线程" }
                }
            });
            unit.Add(new Unit
            {
                Num = 8,
                Title = "同步",
                ChildCatalogues = new List<Unit>
                { 
                    new Unit { Num = 8.01, Title = "lock 语句和线程安全", Sample = "lockSamples" }, 
                    new Unit { Num = 8.02, Title = "Interlocked 类", Sample = "InterlockedSamples" }, 
                    new Unit { Num = 8.03, Title = "Monitor 类", Sample = "MonitorSamples" },
                    new Unit { Num = 8.04, Title = "SpinLock 结构" },
                    new Unit { Num = 8.05, Title = "WaitHandle 基类", Sample = "WaitHandleDelegate" },
                    new Unit { Num = 8.06, Title = "Mutex 类", Sample = "MutexSamples" },
                    new Unit { Num = 8.07, Title = "Semaphore 类", Sample = "SemaphoreSamples" },
                    new Unit { Num = 8.08, Title = "Events 类", Sample = "EventSamples" },
                    new Unit { Num = 8.09, Title = "Barrier 类", Sample = "BarrierSamples" },
                    new Unit { Num = 8.10, Title = "ReaderWriterLockSlim 类", Sample = "ReaderWriterLockSlimSamples" }
                }
            });
            unit.Add(new Unit { Num = 9, Title = "Timer 类", Sample = "TimerSample" });
            unit.Add(new Unit
            {
                Num = 10,
                Title = "数据流",
                ChildCatalogues = new List<Unit> 
                { 
                    new Unit { Num = 10.1, Title = "使用动作块" }, 
                    new Unit { Num = 10.2, Title = "源和目标数据块" }, 
                    new Unit { Num = 10.3, Title = "连接块" } 
                }
            });
            unit.Add(new Unit { Num = 11, Title = "小结" });
        }

        public List<Unit> Catalogues
        {
            get { return unit; }
        }

        public class Unit
        {
            public double Num { get; set; }
            public string Title { get; set; }
            public string Sample { get; set; }
            public List<Unit> ChildCatalogues { get; set; }
        }

        public override string ToString()
        {
            return "第21章 任务、线程和同步";
        }
    }
}
